package com.xbongbong.pro.enums;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.AssembleEnum;
import com.xbongbong.saas.enums.business.BomBillEnum;
import com.xbongbong.saas.enums.business.ClueEnum;
import com.xbongbong.saas.enums.business.CommunicatePlanEnum;
import com.xbongbong.saas.enums.business.ContactEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.ContractOutstockEnum;
import com.xbongbong.saas.enums.business.CustomerCommunicateEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.FundTransferEnum;
import com.xbongbong.saas.enums.business.InstockEnum;
import com.xbongbong.saas.enums.business.InventoryEnum;
import com.xbongbong.saas.enums.business.InvoiceEnum;
import com.xbongbong.saas.enums.business.MarketActivityEnum;
import com.xbongbong.saas.enums.business.OtherExpenseEnum;
import com.xbongbong.saas.enums.business.OtherIncomeEnum;
import com.xbongbong.saas.enums.business.OutstockEnum;
import com.xbongbong.saas.enums.business.PayPlanEnum;
import com.xbongbong.saas.enums.business.PaySheetEnum;
import com.xbongbong.saas.enums.business.PaymentEnum;
import com.xbongbong.saas.enums.business.PaymentSheetEnum;
import com.xbongbong.saas.enums.business.ProductionInstockEnum;
import com.xbongbong.saas.enums.business.ProductionMaterielOutstockEnum;
import com.xbongbong.saas.enums.business.ProductionOrderEnum;
import com.xbongbong.saas.enums.business.PurchaseEnum;
import com.xbongbong.saas.enums.business.PurchaseInstockEnum;
import com.xbongbong.saas.enums.business.PurchaseInvoiceEnum;
import com.xbongbong.saas.enums.business.QuotationEnum;
import com.xbongbong.saas.enums.business.RefundEnum;
import com.xbongbong.saas.enums.business.RefundInstockEnum;
import com.xbongbong.saas.enums.business.ReturnedMaterielInstockEnum;
import com.xbongbong.saas.enums.business.ReturnedPurchaseEnum;
import com.xbongbong.saas.enums.business.ReturnedPurchaseOutstockEnum;
import com.xbongbong.saas.enums.business.SalesOpportunityEnum;
import com.xbongbong.saas.enums.business.SupplierCommunicateEnum;
import com.xbongbong.saas.enums.business.SupplierContactEnum;
import com.xbongbong.saas.enums.business.SupplierEnum;
import com.xbongbong.saas.enums.business.TransferEnum;
import com.xbongbong.saas.enums.business.WarehouseEnum;
import com.xbongbong.saas.enums.business.WorkOrderEnum;
import com.xbongbong.saas.enums.business.WorkOrderOutstockEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * 阶段推进器-执行事件支持字段枚举(saas业务)
 * @author 李少杰
 * @version v1.0.0
 * @date 2022/1/17 10:37
 */
@Getter
public enum StageConditionBusinessFieldEnum {

    /**
     * 客户管理 - businessType: 100
     */
    CUSTOMER_MANAGEMENT(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), new String[] {
            CustomerManagementEnum.NAME_SHORT.getAttr(), CustomerManagementEnum.ADDRESS.getAttr(), CustomerManagementEnum.TYPE.getAttr(), CustomerManagementEnum.SEX.getAttr(),
            CustomerManagementEnum.QQ.getAttr(), CustomerManagementEnum.WE_CHRT.getAttr(), CustomerManagementEnum.GENRE.getAttr(), CustomerManagementEnum.IS_INDIVIDUAL.getAttr(), CustomerManagementEnum.SCALE.getAttr(),
            CustomerManagementEnum.INDUSTRY.getAttr(), CustomerManagementEnum.SOURCE.getAttr(), CustomerManagementEnum.WEBSITE.getAttr(), CustomerManagementEnum.INSTRUCTION.getAttr(), CustomerManagementEnum.COUNTRY.getAttr(),
            CustomerManagementEnum.HOBBIES.getAttr(), CustomerManagementEnum.MEMO.getAttr(), CustomerManagementEnum.FILE.getAttr(),
            CustomerManagementEnum.IMAGE.getAttr(), CustomerManagementEnum.IMPORTANT_DEGREE.getAttr(),
    }),

    /**
     * 联系人 - businessType: 401
     */
    CONTACT(XbbRefTypeEnum.CONTACT.getCode(), new String[]{
            ContactEnum.EMAIL.getAttr(), ContactEnum.QQ.getAttr(), ContactEnum.ADDRESS.getAttr(),
            ContactEnum.ZIP_CODE.getAttr(), ContactEnum.SEX.getAttr(), ContactEnum.HOBBIES.getAttr(), ContactEnum.MEMO.getAttr(), ContactEnum.DEPARTMENT.getAttr(),
            ContactEnum.POSITION.getAttr(), ContactEnum.LEVEL.getAttr(), ContactEnum.RELATIONSHIP.getAttr(),
            ContactEnum.IMPORTANT_DEGREE.getAttr(), ContactEnum.INTIMATE_DEGREE.getAttr(),
    }),

    /**
     * 跟进记录 - businessType: 501
     */
    CUSTOMER_COMMUNICATE(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), new String[]{
            CustomerCommunicateEnum.IMAGES.getAttr(), CustomerCommunicateEnum.TYPE.getAttr(),
            CustomerCommunicateEnum.FILE.getAttr(),
    }),

    /**
     * 销售机会 - businessType: 301
     */
    SALES_OPPORTUNITY(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), new String[]{
            SalesOpportunityEnum.COMPETITOR.getAttr(),SalesOpportunityEnum.WIN_COMPETITOR.getAttr(),
            SalesOpportunityEnum.ESTIMATE_END_TIME.getAttr(), SalesOpportunityEnum.IMPORTANT_DEGREE.getAttr(),
    }),

    /**
     * 报价单 - businessType: 4700
     */
    QUOTATION(XbbRefTypeEnum.QUOTATION.getCode(), new String[]{
            QuotationEnum.QUOTATION_PERSON.getAttr(),
            QuotationEnum.NAME.getAttr(), QuotationEnum.EFFECTIVE_TIME.getAttr(), QuotationEnum.QUOTATION_TIME.getAttr(), QuotationEnum.STATUS.getAttr(),
    }),

    /**
     * 合同订单 - businessType: 201
     */
    CONTRACT(XbbRefTypeEnum.CONTRACT.getCode(), new String[]{
            ContractEnum.SIGN_PERSON.getAttr(), ContractEnum.SIGN_TIME.getAttr(), ContractEnum.TYPE.getAttr(), ContractEnum.PAY_METHOD.getAttr(),
            ContractEnum.EXPRESS_STATUS.getAttr(), ContractEnum.EXPRESS_NAME.getAttr(), ContractEnum.EXPRESS_NO.getAttr(),
            ContractEnum.NAME.getAttr(), ContractEnum.DEADLINE.getAttr(), ContractEnum.STATUS.getAttr(),
    }),

    /**
     * 退货退款 - businessType: 202
     */
    REFUND(XbbRefTypeEnum.REFUND.getCode(), new String[]{
            RefundEnum.SIGN_USER.getAttr(), RefundEnum.SIGN_DATE.getAttr(), RefundEnum.REFUND_REASON.getAttr(), RefundEnum.MEMO.getAttr(),
            RefundEnum.REFUND_NAME.getAttr(), RefundEnum.REFUND_NAME.getAttr(), RefundEnum.PAYMENTS.getAttr(), RefundEnum.PAYMENT_SHEETS.getAttr(),
            RefundEnum.INVOICES.getAttr(),
    }),

    /**
     * 销项发票 - businessType: 901
     */
    INVOICE(XbbRefTypeEnum.INVOICE.getCode(), new String[]{
            InvoiceEnum.INVOICE_NUMBER.getAttr(), InvoiceEnum.INVOICE_TYPE.getAttr(), InvoiceEnum.MEMO.getAttr(),
            InvoiceEnum.INVOICE_DATE.getAttr(), InvoiceEnum.ATTACHMENTS.getAttr(),
    }),

    /**
     * 进项发票 - businessType: 903
     */
    PURCHASE_INVOICE(XbbRefTypeEnum.PURCHASE_INVOICE.getCode(), new String[]{
            PurchaseInvoiceEnum.INVOICE_NUMBER.getAttr(),PurchaseInvoiceEnum.INVOICE_TYPE.getAttr(), PurchaseInvoiceEnum.MEMO.getAttr(),
            PurchaseInvoiceEnum.INVOICE_DATE.getAttr(), PurchaseInvoiceEnum.ATTACHMENTS.getAttr(),
    }),

    /**
     * 回款单 - businessType: 702
     */
    PAYMENT_SHEET(XbbRefTypeEnum.PAYMENT_SHEET.getCode(), new String[]{
            PaymentSheetEnum.MEMO.getAttr(),
    }),

    /**
     * 付款单 - businessType: 802
     */
    PAY_SHEET(XbbRefTypeEnum.PAY_SHEET.getCode(), new String[]{
            PaySheetEnum.PAY_TYPE.getAttr(), PaySheetEnum.MEMO.getAttr(),
    }),

    /**
     * 其他收入单  - businessType: 5710
     */
    OTHER_INCOME(XbbRefTypeEnum.OTHER_INCOME.getCode(), new String[]{
            OtherIncomeEnum.PAY_METHOD.getAttr(), OtherIncomeEnum.MEMO.getAttr(),
            OtherIncomeEnum.INCOME_TIME.getAttr(), OtherIncomeEnum.FILE.getAttr(),
    }),

    /**
     * 其他支出单  - businessType: 5750
     */
    OTHER_EXPENSE(XbbRefTypeEnum.OTHER_EXPENSE.getCode(), new String[]{
            OtherExpenseEnum.PAY_METHOD.getAttr(), OtherIncomeEnum.MEMO.getAttr(),
            OtherIncomeEnum.FILE.getAttr()
    }),

    /**
     * 资金调拨单 - businessType: 5800
     */
    FUND_TRANSFER(XbbRefTypeEnum.FUND_TRANSFER.getCode(), new String[]{
            FundTransferEnum.PAY_METHOD.getAttr(), FundTransferEnum.MEMO.getAttr(),
            FundTransferEnum.FILE.getAttr(),
    }),

    /**
     * 供应商 - businessType: 1001
     */
    SUPPLIER(XbbRefTypeEnum.SUPPLIER.getCode(), new String[]{
            SupplierEnum.SHORT_NAME.getAttr(), SupplierEnum.THUMBNAIL.getAttr(), SupplierEnum.MEMO.getAttr(), SupplierEnum.REGISTERED_CAPITAL.getAttr(),
            SupplierEnum.COUNTRY.getAttr(), SupplierEnum.ADDRESS.getAttr(), SupplierEnum.WEBSITE.getAttr(), SupplierEnum.ANNUAL_OUTPUT.getAttr(),
            SupplierEnum.QUALITY_STANDARD.getAttr(), SupplierEnum.SUPPLY_COST.getAttr(), SupplierEnum.DELIVERY_CAPACITY.getAttr(), SupplierEnum.SERVER_CAPACITY.getAttr(),
            SupplierEnum.CREDIT_LEVEL.getAttr(),
    }),

    /**
     * 供应商联系人 - businessType: 1002
     */
    SUPPLIER_CONTACT(XbbRefTypeEnum.SUPPLIER_CONTACT.getCode(), new String[]{
            SupplierContactEnum.ADDRESS.getAttr(), SupplierContactEnum.EMAIL.getAttr(), SupplierContactEnum.QQ.getAttr(), SupplierContactEnum.SEX.getAttr(),
            SupplierContactEnum.MEMO.getAttr(), SupplierContactEnum.DEPARTMENT.getAttr(), SupplierContactEnum.POSITION.getAttr(), SupplierContactEnum.LEVEL.getAttr()}),

    /**
     * 供应商跟进记录 - businessType: 502
     */
    SUPPLIER_COMMUNICATE(XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode(), new String[]{SupplierCommunicateEnum.TYPE.getAttr(), SupplierCommunicateEnum.IMAGES.getAttr()}),

    /**
     * 采购合同 - businessType: 1101
     */
    PURCHASE(XbbRefTypeEnum.PURCHASE.getCode(), new String[]{
            PurchaseEnum.PAY_METHOD.getAttr(), PurchaseEnum.STATUS.getAttr(), PurchaseEnum.SIGNER_ID.getAttr(), PurchaseEnum.SIGN_TIME.getAttr(), PurchaseEnum.MEMO.getAttr(),
            PurchaseEnum.PURCHASE_NAME.getAttr(), PurchaseEnum.ESTIMATE_ARRIVE_TIME.getAttr(),
    }),

    /**
     * 采购退货单 - businessType: 1201
     */
    RETURNED_PURCHASE(XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), new String[]{
            ReturnedPurchaseEnum.MEMO.getAttr(),
            ReturnedPurchaseEnum.TIME.getAttr(),
    }),

    /**
     * BOM 清单 - businessType: 2601
     */
    BOM_BILL(XbbRefTypeEnum.BOM_BILL.getCode(), new String[]{BomBillEnum.NAME.getAttr(), BomBillEnum.MEMO.getAttr()}),

    /**
     * 生产单 - businessType: 2801
     */
    PRODUCTION_ORDER(XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), new String[]{ProductionOrderEnum.PLAN_TIME.getAttr(), ProductionOrderEnum.MEMO.getAttr()}),

    /**
     * 装配出入库单 - businessType: 1301
     */
    ASSEMBLE(XbbRefTypeEnum.ASSEMBLE.getCode(), new String[]{AssembleEnum.MEMO.getAttr()}),

    /**
     * 盘点单 - businessType: 1701
     */
    INVENTORY(XbbRefTypeEnum.INVENTORY.getCode(), new String[]{
            InventoryEnum.MEMO.getAttr(),
            InventoryEnum.TIME.getAttr(),
    }),

    /**
     * 调拨单 - businessType: 1601
     */
    TRANSFER(XbbRefTypeEnum.TRANSFER.getCode(), new String[]{
            TransferEnum.MEMO.getAttr(),
            TransferEnum.TRANSFER_TIME.getAttr(),
    }),

    /**
     * 采购入库单 - businessType: 1404
     */
    PURCHASE_INSTOCK(XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(), new String[]{
            PurchaseInstockEnum.MEMO.getAttr(),
            PurchaseInstockEnum.TIME.getAttr(),
    }),

    /**
     * 销售退货入库单 - businessType: 1405
     */
    REFUND_INSTOCK(XbbRefTypeEnum.REFUND_INSTOCK.getCode(), new String[]{RefundInstockEnum.MEMO.getAttr()}),

    /**
     * 其他入库单 - businessType: 1406
     */
    OTHER_INSTOCK(XbbRefTypeEnum.OTHER_INSTOCK.getCode(), new String[]{InstockEnum.MEMO.getAttr()}),

    /**
     * 生产入库单 - businessType: 1407
     */
    PRODUCTION_INSTOCK(XbbRefTypeEnum.PRODUCTION_INSTOCK.getCode(), new String[]{ProductionInstockEnum.MEMO.getAttr()}),

    /**
     * 生产退料单 - businessType: 1408
     */
    RETURNED_MATERIEL_INSTOCK(XbbRefTypeEnum.RETURNED_MATERIEL_INSTOCK.getCode(), new String[]{ReturnedMaterielInstockEnum.MEMO.getAttr()}),

    /**
     * 销售出库单 - businessType: 1504
     */
    CONTRACT_OUTSTOCK(XbbRefTypeEnum.CONTRACT_OUTSTOCK.getCode(), new String[]{ContractOutstockEnum.MEMO.getAttr()}),

    /**
     * 采购退货出库单 - businessType: 1505
     */
    RETURNED_PURCHASE_OUTSTOCK(XbbRefTypeEnum.RETURNED_PURCHASE_OUTSTOCK.getCode(), new String[]{ReturnedPurchaseOutstockEnum.MEMO.getAttr()}),

    /**
     * 其他出库单 - businessType: 1506
     */
    OTHER_OUTSTOCK(XbbRefTypeEnum.OTHER_OUTSTOCK.getCode(), new String[]{OutstockEnum.MEMO.getAttr()}),

    /**
     * 生产领料单 - businessType: 1507
     */
    PRODUCTION_MATERIEL_OUTSTOCK(XbbRefTypeEnum.PRODUCTION_MATERIEL_OUTSTOCK.getCode(), new String[]{ProductionMaterielOutstockEnum.MEMO.getAttr()}),

    /**
     * 仓库 - businessType: 1801
     */
    WAREHOUSE(XbbRefTypeEnum.WAREHOUSE.getCode(), new String[]{WarehouseEnum.ADDRESS.getAttr(), WarehouseEnum.MEMO.getAttr()}),

    /**
     * 市场活动 - businessType: 8100
     */
    MARKET_ACTIVITY(XbbRefTypeEnum.MARKET_ACTIVITY.getCode(), new String[]{
            MarketActivityEnum.GENRE.getAttr(), MarketActivityEnum.ESTIMATE_COST.getAttr(), MarketActivityEnum.REAL_COST.getAttr(), MarketActivityEnum.ESTIMATE_INCOME.getAttr(),
            MarketActivityEnum.REAL_INCOME.getAttr(), MarketActivityEnum.CAPTION.getAttr(), MarketActivityEnum.MEMO.getAttr(),
            MarketActivityEnum.START_TIME.getAttr(), MarketActivityEnum.END_TIME.getAttr(), MarketActivityEnum.LABEL.getAttr(), MarketActivityEnum.ADDRESS.getAttr(),
    }),

    /**
     * 线索 - businessType: 8000
     */
    CLUE(XbbRefTypeEnum.CLUE.getCode(), new String[]{
            ClueEnum.CLUE_SOURCE.getAttr(), ClueEnum.INVALID_REASON.getAttr(), ClueEnum.INVALID_MEMO.getAttr(), ClueEnum.MEMO.getAttr(), ClueEnum.FILE.getAttr(),
            ClueEnum.ADDRESS.getAttr(), ClueEnum.LABEL.getAttr(),  ClueEnum.IMAGE.getAttr(),  ClueEnum.CONTACT.getAttr(),
    }),

    /**
     * 应收款 - businessType：701
     *
     */
    PAYMENT(XbbRefTypeEnum.PAYMENT.getCode(), new String[]{
            PaymentEnum.ESTIMATE_TIME.getAttr(), PaymentEnum.MEMO.getAttr(),
    }),

    /**
     * 付款计划 - businessType：801
     */
    PAY_PLAN_SUBFORM(XbbRefTypeEnum.PAY_PLAN.getCode(), new String[]{
            PayPlanEnum.PAYMENT_METHOD.getAttr(), PayPlanEnum.ESTIMATE_TIME.getAttr(), PayPlanEnum.MEMO.getAttr(),
    }),
    /**
     * 访客计划 - businessType：601
     */
    COMMUNICATEPLAN(XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(), new String[]{
            CommunicatePlanEnum.TARGET.getAttr(), CommunicatePlanEnum.MEMO.getAttr(),
    }),

    /**
     * 工单出库 - businessType：1508
     */
    WORK_ORDER_OUTSTOCK(XbbRefTypeEnum.WORK_ORDER_OUTSTOCK.getCode(), new String[]{
            WorkOrderOutstockEnum.EXPRESS_NO.getAttr(), WorkOrderOutstockEnum.MEMO.getAttr(),
    }),

    /**
     * 工单 - businessType：2301
     *
     */
    WORK_ORDER(XbbRefTypeEnum.WORK_ORDER.getCode(), new String[]{WorkOrderEnum.MEMO.getAttr(), WorkOrderEnum.EMERGENCY_LEVEL.getAttr()}),

    // 新工单
    WOKR_ORDER_V2(XbbRefTypeEnum.WORK_ORDER_V2.getCode(),new String[]{"text_1","text_3","date_1","date_2","address_1"}),

    ;

    /**
     * 业务类型
     */
    private final int code;

    /**
     * 字段数组
     */
    private final String[] attrArray;

    StageConditionBusinessFieldEnum (int code, String[] attrArray) {
        this.code = code;
        this.attrArray = attrArray;
    }

    /**
     * 根据业务类型查询所有字段
     * @param code 业务类型
     * @return 该业务支持的所有字段
     */
    public static JSONArray getAttrsByCode (Integer code) {
        JSONArray array = new JSONArray();
        for (StageConditionBusinessFieldEnum cacheCode : values()) {
            if (Objects.equals(code, cacheCode.getCode())) {
                String[] attrArray = cacheCode.getAttrArray();
                array = JSONArray.parseArray(JSON.toJSONString(attrArray));
                return array;
            }
        }
        return array;
    }
}
